package a32

import scala.annotation.tailrec

object Teil2 {

  def main(args: Array[String]): Unit = {
    val sLst = List("Hallo", "Welt");
    println(getChars(sLst, 0, 0))
  }

  @tailrec
  def getChars(list: List[String], i: Int, si: Int, chars: Char*): List[Char] = {

    if (i < list.length) {
      if (si < list(i).length()) {
        getChars(list, i, si + 1, (chars :+ list(i)(si)): _*)
      } else {
        getChars(list, i + 1, 0, chars: _*)
      }
    } else {
      chars.toList
    }

  }
}